<template>
  <div class="offline-container">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="120px"
      class="demo-ruleForm"
    >
      <el-form-item label="线下盒子名称：" prop="offline_box_name" style="white-space:nowrap;">
        <el-input v-model="ruleForm.offline_box_name" style="width: 400px; height: 36px"></el-input>
      </el-form-item>
      <el-form-item label="线下盒子价格：" prop="offline_box_price">
        <el-input v-model="ruleForm.offline_box_price" style="width: 400px; height: 36px"></el-input>
      </el-form-item>
    </el-form>
    <div class="upload">
      <div class="upload-top">
        <el-upload
          class="avatar-uploader"
          action="http://yaya.izhixiu.cn/api/common/upload"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload"
          :data="uploadData"
        >
          <el-button>上传图片</el-button>
        </el-upload>
        <span class="desc">注：建议尺寸750*584px</span>
      </div>
      <div class="pic-wrapper" v-if="ruleForm.offline_box_photo">
        <div class="pic" style="margin-bottom: 20px" v-for="(item,index) of ruleForm.offline_box_photo" :key="index">
          <img v-if="ruleForm.offline_box_photo.length" :src="item" class="avatar" />
          <i v-else class="el-icon-picture avatar-uploader-icon"></i>
          <i class="el-icon-close" @click="deleteAvatar(index)"></i>
        </div>
      </div>
      <div v-else class="pic-wrapper">
        <div class="pic" style="margin-bottom: 20px">
          <i class="el-icon-picture avatar-uploader-icon"></i>
          <i class="el-icon-close"></i>
        </div>
      </div>
    </div>
    <el-form label-width="120px">
      <el-form-item label="盒子介绍：">
        <Ueditor ref="ue"></Ueditor>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import Ueditor from "@/common/editor/editor";
export default {
  props: {
    ruleForm: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    
    return {
      // fileList: [],
      is_first: true,
      uploadData: {},
      imageUrl: "",
      rules: {
        offline_box_name: [
          { required: true, message: "请输入线下盒子名称", trigger: "blur" }
        ],
        offline_box_price: [
          { required: true, message: "请输入线下盒子价格", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    deleteAvatar(index) {
      this.ruleForm.offline_box_photo.splice(index, 1)
    },
    beforeAvatarUpload(file) {
      this.uploadData.photo = file;
    },
    handleAvatarSuccess(res, file) {
      this.ruleForm.offline_box_photo.push(res.data.photo)
    },
    formatParams() {
      let content = this.$refs.ue.content
      this.ruleForm.offline_box_description = content;
      this.$emit('sendParamsSecond', this.ruleForm)

    }
  },
  watch: {
    ruleForm() {
      if (this.is_first) {
        // this.$refs.ue.content = 
      }
    }
  },
  components: {
    Ueditor
  }
};
</script>
<style lang="scss" scoped>
.offline-container {
  padding: 20px;
  position: relative;
  top: 135px;
  margin-bottom: 150px;
}
.upload {
  .upload-top {
    display: flex;
    .desc {
      color: red;
      font-size: 14px;
      font-family: Roboto;
      line-height: 38px;
      margin-left: 10px;
    }
  }

  position: relative;
  .avatar-uploader {
    margin-left: 120px;
  }
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    .el-button {
      display: block;
      width: 126px;
      height: 38px;
      background: #e9e9e9;
      color: #444;
      position: relative;
      left: 50%;
      transform: translateX(-50%);
      margin-bottom: 21px;
    }
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409eff;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 144px;
    height: 144px;
    line-height: 144px;
    text-align: center;
    background: #ccc;
  }

  .avatar {
    width: 144px;
    height: 144px;
    display: block;
  }
  .pic-wrapper{
    display: flex;
    justify-content: flex-start;
    padding-left: 100px;
  }
  .pic {
    margin-left: 20px;
    position: relative;
    .el-icon-close {
      position: absolute;
      top: -5px;
      right: -5px;
      background: #000;
      border-radius: 50%;
      color: #fff;
      font-weight: bold;
    }
  }
}
</style>